
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<div class="modal" id="addLineDiv" tabindex="-1" role="dialog" aria-hidden="true">

	<div class="modal-dialog" role="document" style="max-width: 800px;">

		<div class="modal-content animated bounceInRight">

			<div class="modal-header">
				<h4 class="modal-title">任务行编辑</h4>
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
			</div>

			<div class="modal-body" style="padding-bottom: 20px;">
				<%-- 导入提示信息框 --%>
			    <c:if test="${hint!=null&&hint!=''}">
			   		<jsp:include page="../../common/alert/alert.jsp">
			   			<jsp:param value="${hint}" name="alertType"/>
			   			<jsp:param value="${alertMessage}" name="alertMessage"/>
			   		</jsp:include>
			    </c:if>
			
				<form id="cform">
					<div class="form-group row">
						<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>任务编码</label>
						<div class="col-sm-4">
							<input id="confLineCode" name="confLineCode" type="text" class="form-control" value="${requestScope.cuxWorkflowConfLine.confLineCode}">
							<span class="help-block m-b-none" style="color: silver;">推荐使用工作流的编码+数字</span>
						</div>
					
						<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>任务名称</label>
						<div class="col-sm-4">
							<input id="taskName" name="taskName" type="text" class="form-control" value="${requestScope.cuxWorkflowConfLine.taskName}">
						</div>
					</div>
					<div class="hr-line-dashed"></div>
					
					<div class="form-group row">
						<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>任务顺序</label>
						<div class="col-sm-4">
							<input id="orderNumber" name="orderNumber" type="text" class="form-control" value="${requestScope.cuxWorkflowConfLine.orderNumber}">
							<span class="help-block m-b-none" style="color: silver;">当前任务所处的节点位置，从1开始</span>
						</div>
		
						<label class="col-sm-2 col-form-label">任务描述</label>
						<div class="col-sm-4">
							<input id="taskDesc" name="taskDesc" type="text" class="form-control" value="${requestScope.cuxWorkflowConfLine.taskDesc}">
						</div>
					</div>
					<div class="hr-line-dashed"></div>
				
					<div class="form-group row">
						<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>审批部门</label>
						<div class="col-sm-4">
							<select class="chosen-select form-control" name="approveDepartment" id="approveDepartment">
	                        	<option value="" selected="selected">请选择...</option>
	                        	<option value="sys_wf_department0">提交人部门--工作流</option>
	                        	<option value="sys_wf_department1">提交人上级部门--工作流</option>
	                        	<option value="sys_wf_department2">提交人上上级部门--工作流</option>
	                        	<c:forEach items="${requestScope.hrDepartmentList}" var="hrDepartment">
	                        		<option value="${hrDepartment.departmentCode}">${hrDepartment.segmentDesc}</option>
	                        	</c:forEach>
	                        </select>
						</div>
					
						<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>审批岗位</label>
						<div class="col-sm-4">
							<select class="chosen-select form-control" name="approvePosition" id="approvePosition">
	                        	<option value="" selected="selected">请选择...</option>
	                        	<c:forEach items="${requestScope.hrPositionList}" var="hrPosition">
	                        		<option value="${hrPosition.positionCode}">${hrPosition.positionName}</option>
	                        	</c:forEach>
	                        </select>
						</div>
					</div>
					<div class="hr-line-dashed"></div>
					
					<div class="form-group row">
						<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>审批人</label>
						<div class="col-sm-4">
							<select class="chosen-select form-control" name="approvePerson" id="approvePerson">
	                        	<option value="" selected="selected">请选择...</option>
	                        	<c:forEach items="${requestScope.hrStaffList}" var="hrStaff">
	                        		<option value="${hrStaff.staffCode}">${hrStaff.staffName}</option>
	                        	</c:forEach>
	                        </select>
	                        <span class="help-block m-b-none" style="color: silver;">审批人或审批部门和审批岗位只需填写一个即可，填写审批部门后审批岗位必填</span>
						</div>
					
						<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>当前分支条件</label>
						<div class="col-sm-4">
							<input id="branchCondition" name="branchCondition" type="text" class="form-control" value="${requestScope.cuxWorkflowConfLine.branchCondition}">
							<span class="help-block m-b-none" style="color: silver;">分支条件结果只支持布尔值，举例：number > 10 && name == 'redragon'；说明：number/name为参数，符号包括（算数运算符、关系运算符、逻辑运算符）</span>
						</div>
					</div>
					<div class="hr-line-dashed"></div>
					
					<div class="form-group row">
						<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>父任务</label>
						<div class="col-sm-4">
							<select class="chosen-select form-control" name="parentTaskCode" id="parentTaskCode">
	                        	<option value="" selected="selected">请选择...</option>
	                        	<option value="sys_wf_task_start">开始</option>
	                        	<c:forEach items="${requestScope.cuxWorkflowConfLineList}" var="cuxWorkflowConfLine">
	                        		<option value="${cuxWorkflowConfLine.confLineCode}">${cuxWorkflowConfLine.taskName}(${cuxWorkflowConfLine.orderNumber})</option>
	                        	</c:forEach>
	                        </select>
	                        <span class="help-block m-b-none" style="color: silver;">选择下一流转的任务节点</span>
						</div>

						<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>状态</label>
						<div class="col-sm-4">
							<select class="form-control m-b" name="lineStatus" id="lineStatus">
								<option value="Y" selected="selected">有效</option>
								<option value="N">无效</option>
							</select>
						</div>
					</div>
					<div class="hr-line-dashed"></div>

					<div class="form-group row m-b-none">
						<div class="col-sm-12 col-sm-offset-2 text-right">
							<button class="btn btn-white btn-lg" type="button"
								data-dismiss="modal">返回</button>
							&nbsp;
							<button
								class="ladda-button ladda-button-demo btn btn-primary btn-lg"
								data-style="expand-right">
								&nbsp;&nbsp;确定&nbsp;&nbsp;<i class="fa fa-check-square-o"></i>
							</button>
						</div>
					</div>
					
					<input type="hidden" id="confHeadCode" name="confHeadCode" value="${param.confHeadCode}"> 
					<input type="hidden" id="confLineId" name="confLineId" value="${requestScope.cuxWorkflowConfLine.confLineId}"> 
					<input type="hidden" id="createdDate" name="createdDate" value="${requestScope.cuxWorkflowConfLine.createdDate}"> 
					<input type="hidden" id="createdBy" name="createdBy" value="${requestScope.cuxWorkflowConfLine.createdBy}">
				</form>
			</div>

		</div>

	</div>

</div>

<!-- Chosen -->
<script src="js/plugins/chosen/chosen.jquery.js"></script>

<script>
	$(document).ready(function() {
		//初始化status
		if("${requestScope.cuxWorkflowConfLine.status}"!=""){
			$("#status").val("${requestScope.cuxWorkflowConfLine.status}");
		}
		//初始化approveDepartment
		if("${requestScope.cuxWorkflowConfLine.approveDepartment}"!=""){
			$("#approveDepartment").val("${requestScope.cuxWorkflowConfLine.approveDepartment}");
		}
		//初始化approvePosition
		if("${requestScope.cuxWorkflowConfLine.approvePosition}"!=""){
			$("#approvePosition").val("${requestScope.cuxWorkflowConfLine.approvePosition}");
		}
		//初始化approvePerson
		if("${requestScope.cuxWorkflowConfLine.approvePerson}"!=""){
			$("#approvePerson").val("${requestScope.cuxWorkflowConfLine.approvePerson}");
		}
		//初始化parentTaskCode
		if("${requestScope.cuxWorkflowConfLine.parentTaskCode}"!=""){
			$("#parentTaskCode").val("${requestScope.cuxWorkflowConfLine.parentTaskCode}");
		}
		
		//初始化chosen-select
		$('.chosen-select').chosen({width: "100%"});
		
		
		
		//表单提交
		var l = $('.ladda-button-demo').ladda();

		l.click(function() {
			$("#cform").valid();
			//l.ladda('stop');
		});

		$("#cform").validate({
			rules : {
				confLineCode : {
					required : true,
				},
				orderNumber : {
					required : true,
					digits : true,
					min: 1
				},
				taskName : {
					required : true,
				},
				branchCondition : {
					required : true,
				},
				parentTaskCode : {
					required : true,
				},
				status : {
					required : true,
				}
			},
			submitHandler: function(form) {
				var submitFlag = "Y";
				
				if($("#approvePerson").val()==""){
					if($("#approveDepartment").val()==""||$("#approvePosition").val()==""){
						submitFlag = "N";
						redragonJS.alert("审批部门和审批岗位必填/审批人必填");
					}
				}else{
					if($("#approveDepartment").val()!=""||$("#approvePosition").val()!=""){
						submitFlag = "N";
						redragonJS.alert("审批部门和审批岗位无需填写");
					}
				}
				
				if(submitFlag=="Y"){
					l.ladda('start');
					editLine();
				}
		    }
		});
		
	});
	
	//异步编辑行
	function editLine(){
		redragonJS.loading("tabDiv");
	
		$.ajax({
			type: "post",
			url: "web/cuxWorkflowConfLine/editCuxWorkflowConfLine",
			data: {"confLineCode": $("#confLineCode").val(), "taskName": $("#taskName").val(), "orderNumber": $("#orderNumber").val(), "taskDesc": $("#taskDesc").val(),
				   "status": $("#lineStatus").val(), "confLineId": $("#confLineId").val(), "createdDate": $("#createdDate").val(), "createdBy": $("#createdBy").val(), 
				   "approveDepartment": $("#approveDepartment").val(), "approvePosition": $("#approvePosition").val(), "approvePerson": $("#approvePerson").val(), 
				   "branchCondition": $("#branchCondition").val(), "parentTaskCode": $("#parentTaskCode").val(), "confHeadCode": $("#confHeadCode").val()},
			async: false,
			dataType: "html",
			cache: false,
			success: function(data){
				redragonJS.removeLoading("tabDiv");
				$('#addLineDiv').modal('hide');
				$('.ladda-button-demo').ladda('stop');
				
				var json = JSON.parse(data);
				if(json.result=="success"){
					getLineTab($("#confHeadCode").val());
				}else{
					redragonJS.alert("编辑任务行错误");
				}
				
			},
			error: function(XMLHttpRequest, textStatus, errorThrown){
				redragonJS.alert(textStatus);
			}
		});
	}

</script>
